package com.ruoyi.supervise.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.supervise.domain.CompanyPoorInfoEntuty;
import com.ruoyi.supervise.domain.CompanyWellInfoEntity;
import com.ruoyi.supervise.domain.Enterprise;
import com.ruoyi.supervise.domain.IGMAuditRecord;
import com.ruoyi.supervise.domain.IGMBehavioStandard;
import com.ruoyi.supervise.domain.IGMCompanyPoorInfo;
import com.ruoyi.supervise.domain.IGMCompanyWellInfo;
import com.ruoyi.supervise.domain.IGMIntegrityApplyInfo;
import com.ruoyi.supervise.domain.IGMPersonalPoorInfo;
import com.ruoyi.supervise.domain.IGMPersonalWellInfo;
import com.ruoyi.supervise.domain.PersonalPoorInfoEntity;
import com.ruoyi.supervise.domain.PersonalWellInfoEntity;
import com.ruoyi.supervise.domain.StandardEntity;
import com.ruoyi.supervise.mapper.IntegrityInformationAddMapper;
import com.ruoyi.supervise.mapper.IntegrityInformationMapper;
import com.ruoyi.supervise.service.IIntegrityInformationAddService;
import com.ruoyi.supervise.util.XMLUtil;
import com.ruoyi.system.domain.SysUser;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;


/**
 * @ClassName: IntegrityInformationAddServiceImpl
 * @Description: 行为登记impl
 * @Author wtj
 * @DateTime 2020年6月4日 下午4:16:01
 */
@Service
@DataSource(value = DataSourceType.SLAVE)
public class IntegrityInformationAddServiceImpl implements IIntegrityInformationAddService 
{
    @Autowired
    private IntegrityInformationAddMapper integrityInformationAddMapper;
    
    @Autowired
    private IntegrityInformationMapper integrityInformationMapper;

	@Override
	public List<IGMBehavioStandard> selectIGMBehavioStandardList(IGMBehavioStandard igmbs) {
		// TODO Auto-generated method stub
		return integrityInformationAddMapper.selectIGMBehavioStandardList(igmbs);
	}

	@Override
	public List<IGMIntegrityApplyInfo> selectEnterGoodIGMIntegrityApplyInfoList(IGMIntegrityApplyInfo igmai) {
		igmai.setApplyType("企业良好");
		SysUser currentUser = ShiroUtils.getSysUser();
		if(!currentUser.getLoginName().equals("admin") && !currentUser.getLoginName().trim().equals("lingshui")) {
			igmai.setOperLoginName(currentUser.getLoginName());
		}
		List<IGMIntegrityApplyInfo> igmaiList = integrityInformationAddMapper.selectIGMIntegrityApplyInfoList(igmai);
		if(!StringUtils.isEmpty(igmaiList)) {
			for(IGMIntegrityApplyInfo igmiai:igmaiList) {
				CompanyWellInfoEntity cwea = (CompanyWellInfoEntity) XMLUtil.convertXmlStrToObject(CompanyWellInfoEntity.class, igmiai.getCompanyWellInfo());
				if(!StringUtils.isEmpty(cwea.getGuid())) {
					IGMCompanyWellInfo igmcwi = integrityInformationMapper.selectIGMCompanyWellInfoByGuid(cwea.getGuid());
					if(igmcwi!=null) {
						cwea.setUndoApplyDate(igmcwi.getUndoApplyDate());
					}
				}
				igmiai.setCompanyWellInfoEntity(cwea);
			}
		}
		return igmaiList;
	}

	@Override
	public List<String> selectIGMIntegrityApplyInfoPunishObject(String identifyType) {
		// TODO Auto-generated method stub
		return integrityInformationAddMapper.selectIGMIntegrityApplyInfoPunishObject(identifyType);
	}

	@Override
	public IGMBehavioStandard selectIGMBehavioStandardByGuid(String guid) {
		IGMBehavioStandard igmbs = integrityInformationAddMapper.selectIGMBehavioStandardByGuid(guid);
		if(igmbs != null) {
			if(StringUtils.isEmpty(igmbs.getMaxScores()) || igmbs.getMaxScores().equals("0") || igmbs.getMaxScores().equals("0.0")) {
				igmbs.setMaxScores("无上限");
			}
		}
		return igmbs;
	}

	@Override
	public String sumEnterGoodAddedScores(IGMCompanyWellInfo igmcwi) {
		String pointsAdded = integrityInformationAddMapper.sumEnterGoodAddedScores(igmcwi);
		if(StringUtils.isEmpty(pointsAdded)) {
			pointsAdded = "0";
    	}
		return pointsAdded;
	}

	@Override
	public List<Enterprise> enterTableList(Enterprise enter) {
		// TODO Auto-generated method stub
		return integrityInformationAddMapper.enterTableList(enter);
	}

	@Override
	public int enterprisesGoodBehaviorSaveAndReport(CompanyWellInfoEntity cwie,String MaxScores) {
		String selectScore = cwie.getScore();
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
    	igmai.setGuid(IdUtil.randomUUID());
    	igmai.setName(cwie.getCompanyName());
    	igmai.setDescription(cwie.getBehaviorDescription());
    	igmai.setApplyType("企业良好");
    	igmai.setArea("陵水县");
    	SysUser currentUser = ShiroUtils.getSysUser();
    	igmai.setOperLoginName(currentUser.getLoginName());
    	igmai.setOperName(currentUser.getUserName());
    	igmai.setOperUnitGuid(String.valueOf(currentUser.getDeptId()));
    	igmai.setCompanyPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setPersonalWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setPersonnalPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	igmai.setApplyWay("登记");
    	if(cwie.getSaveOrReport().equals("保存")) {
    		igmai.setState("未上报");
    	}else if(cwie.getSaveOrReport().equals("上报")) {
    		igmai.setState("已上报");
    		igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	}
    	StandardEntity se = integrityInformationAddMapper.selectStandardEntityByGuid(cwie.getBehaviorCode());
    	cwie.setStandard(se);
    	cwie.setGuid(IdUtil.randomUUID());
    	cwie.setRegPerson(currentUser.getUserName());
    	cwie.setOwnerGuid(currentUser.getLoginName());
    	cwie.setRegDepartment(currentUser.getDept().getDeptName());
    	cwie.setRegDepartmentGuid(String.valueOf(currentUser.getDeptId()));
    	cwie.setSaveOrReport(null);
    	if("无上限".equals(MaxScores)) {
    		cwie.setScore(selectScore);
    	}else {
    		if(Double.parseDouble(cwie.getPointsAdded()) < Double.parseDouble(se.getMaxScores())) {
        		if((Double.parseDouble(cwie.getPointsAdded()) + Double.parseDouble(selectScore)) < Double.parseDouble(se.getMaxScores())) {
        			cwie.setScore(selectScore);
        		}else if((Double.parseDouble(cwie.getPointsAdded()) + Double.parseDouble(selectScore)) > Double.parseDouble(se.getMaxScores())) {
        			cwie.setScore(String.valueOf(Double.parseDouble(se.getMaxScores()) - Double.parseDouble(cwie.getPointsAdded())));
        		}
        	}else if(Double.parseDouble(cwie.getPointsAdded()) >= Double.parseDouble(se.getMaxScores())) {
        		cwie.setScore("0");
        	}
    	}
    	//cwie.setPointsAdded(null);
    	cwie.setInSource("手动添加");
    	igmai.setCompanyWellInfo(XMLUtil.convertToXml(cwie));
		return integrityInformationAddMapper.insertIGMIntegrityApplyInfo(igmai);
	}

	@Override
	public IGMIntegrityApplyInfo selectIGMIntegrityApplyInfoByGuid(String guid) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(guid);
		applyInfo.setCompanyWellInfoEntity((CompanyWellInfoEntity)XMLUtil.convertXmlStrToObject(CompanyWellInfoEntity.class,applyInfo.getCompanyWellInfo()));
		applyInfo.setCompanyPoorInfoEntuty((CompanyPoorInfoEntuty)XMLUtil.convertXmlStrToObject(CompanyPoorInfoEntuty.class,applyInfo.getCompanyPoorInfo()));
		applyInfo.setPersonalWellInfoEntity((PersonalWellInfoEntity)XMLUtil.convertXmlStrToObject(PersonalWellInfoEntity.class,applyInfo.getPersonalWellInfo()));
		applyInfo.setPersonnalPoorInfoEntity((PersonalPoorInfoEntity)XMLUtil.convertXmlStrToObject(PersonalPoorInfoEntity.class,applyInfo.getPersonnalPoorInfo()));
		return applyInfo;
	}

	@Override
	public int updateEnterprisesGoodBehavior(CompanyWellInfoEntity cwie,int type,String MaxScores) {
		if(type == 1) {
			IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(cwie.getIGMIntegrityApplyInfoGuid());
			if(applyInfo != null && !StringUtils.isEmpty(applyInfo.getCompanyWellInfo())) {
				CompanyWellInfoEntity cwea = (CompanyWellInfoEntity) XMLUtil.convertXmlStrToObject(CompanyWellInfoEntity.class, applyInfo.getCompanyWellInfo());
				if(!StringUtils.isEmpty(cwie.getMaterials())) {
					if(!cwea.getMaterials().equals(cwie.getMaterials())) {
						cwie.setMaterials(null);
					}
				}else {
					cwie.setMaterials(null);
				}
			}else {
				cwie.setMaterials(null);
			}
		}
		String selectScore = cwie.getScore();
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
		igmai.setGuid(cwie.getIGMIntegrityApplyInfoGuid());
		cwie.setIGMIntegrityApplyInfoGuid(null);
		igmai.setName(cwie.getCompanyName());
		igmai.setDescription(cwie.getBehaviorDescription());
		if(cwie.getSaveOrReport().equals("保存")) {
    		igmai.setState("未上报");
    		igmai.setReportDate(null);
    	}else if(cwie.getSaveOrReport().equals("上报")) {
    		igmai.setState("已上报");
    		igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	}
		StandardEntity se = integrityInformationAddMapper.selectStandardEntityByGuid(cwie.getBehaviorCode());
		cwie.setStandard(se);
		cwie.setSaveOrReport(null);
		if("无上限".equals(MaxScores)) {
			cwie.setScore(selectScore);
		}else {
			if(Double.parseDouble(cwie.getPointsAdded()) < Double.parseDouble(se.getMaxScores())) {
	    		if((Double.parseDouble(cwie.getPointsAdded()) + Double.parseDouble(selectScore)) < Double.parseDouble(se.getMaxScores())) {
	    			cwie.setScore(selectScore);
	    		}else if((Double.parseDouble(cwie.getPointsAdded()) + Double.parseDouble(selectScore)) > Double.parseDouble(se.getMaxScores())) {
	    			cwie.setScore(String.valueOf(Double.parseDouble(se.getMaxScores()) - Double.parseDouble(cwie.getPointsAdded())));
	    		}
	    	}else if(Double.parseDouble(cwie.getPointsAdded()) >= Double.parseDouble(se.getMaxScores())) {
	    		cwie.setScore("0");
	    	}
		}
		cwie.setInSource("手动添加");
    	igmai.setCompanyWellInfo(XMLUtil.convertToXml(cwie));
		return integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
	}

	@Override
	public List<IGMIntegrityApplyInfo> selectEnterBadIGMIntegrityApplyInfoList(IGMIntegrityApplyInfo igmai) {
		igmai.setApplyType("企业不良");
		SysUser currentUser = ShiroUtils.getSysUser();
		if(!currentUser.getLoginName().equals("admin") && !currentUser.getLoginName().trim().equals("lingshui")) {
			igmai.setOperLoginName(currentUser.getLoginName());
		}
		List<IGMIntegrityApplyInfo> igmaiList = integrityInformationAddMapper.selectIGMIntegrityApplyInfoList(igmai);
		if(!StringUtils.isEmpty(igmaiList)) {
			for(IGMIntegrityApplyInfo igmiai:igmaiList) {
				CompanyPoorInfoEntuty cpie = (CompanyPoorInfoEntuty) XMLUtil.convertXmlStrToObject(CompanyPoorInfoEntuty.class, igmiai.getCompanyPoorInfo());
				if(!StringUtils.isEmpty(cpie.getGuid())) {
					IGMCompanyPoorInfo igmcpi = integrityInformationMapper.selectIGMCompanyPoorInfoByGuid(cpie.getGuid());
					if(igmcpi!=null) {
						cpie.setUndoApplyDate(igmcpi.getUndoApplyDate());
					}
				}
				igmiai.setCompanyPoorInfoEntuty(cpie);
			}
		}
		return igmaiList;
	}

	@Override
	public int enterprisesBadBehaviorSaveAndReport(CompanyPoorInfoEntuty cpie,String MaxScores) {
		String selectScore = cpie.getPenaltyScores();
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
		igmai.setGuid(IdUtil.randomUUID());
    	igmai.setName(cpie.getCompanyName());
    	igmai.setDescription(cpie.getBehaviorDescription());
    	igmai.setApplyType("企业不良");
    	igmai.setArea("陵水县");
    	SysUser currentUser = ShiroUtils.getSysUser();
    	igmai.setOperLoginName(currentUser.getLoginName());
    	igmai.setOperName(currentUser.getUserName());
    	igmai.setOperUnitGuid(String.valueOf(currentUser.getDeptId()));
    	igmai.setCompanyWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setPersonalWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setPersonnalPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	igmai.setApplyWay("登记");
    	if(cpie.getSaveOrReport().equals("保存")) {
    		igmai.setState("未上报");
    	}else if(cpie.getSaveOrReport().equals("上报")) {
    		igmai.setState("已上报");
    		cpie.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    		igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	}
    	StandardEntity se = integrityInformationAddMapper.selectStandardEntityByGuid(cpie.getBehaviorCode());
    	cpie.setStandard(se);
    	cpie.setGuid(IdUtil.randomUUID());
    	cpie.setRegisterName(currentUser.getUserName());
    	cpie.setLoginId(currentUser.getLoginName());
    	cpie.setRegisterDept(currentUser.getDept().getDeptName());
    	cpie.setRegisterDeptGuid(String.valueOf(currentUser.getDeptId()));
    	cpie.setSaveOrReport(null);
    	if("无上限".equals(MaxScores)) {
    		cpie.setPenaltyScores(selectScore);
    	}else {
    		if(Double.parseDouble(cpie.getPointsDeducted()) < Double.parseDouble(se.getMaxScores())) {
        		if((Double.parseDouble(cpie.getPointsDeducted()) + Double.parseDouble(selectScore)) < Double.parseDouble(se.getMaxScores())) {
        			cpie.setPenaltyScores(selectScore);
        		}else if((Double.parseDouble(cpie.getPointsDeducted()) + Double.parseDouble(selectScore)) > Double.parseDouble(se.getMaxScores())) {
        			cpie.setPenaltyScores(String.valueOf(Double.parseDouble(se.getMaxScores()) - Double.parseDouble(cpie.getPointsDeducted())));
        		}
        	}else if(Double.parseDouble(cpie.getPointsDeducted()) >= Double.parseDouble(se.getMaxScores())) {
        		cpie.setPenaltyScores("0");
        	}
    	}
    	cpie.setInSource("手动添加");
    	igmai.setCompanyPoorInfo(XMLUtil.convertToXml(cpie));
    	return integrityInformationAddMapper.insertIGMIntegrityApplyInfo(igmai);
	}

	@Override
	public StandardEntity selectStandardEntityByGuid(String guid) {
		// TODO Auto-generated method stub
		return integrityInformationAddMapper.selectStandardEntityByGuid(guid);
	}

	@Override
	public int updateEnterprisesBadBehavior(CompanyPoorInfoEntuty cpie, int type,String MaxScores) {
		if(type == 1) {
			IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(cpie.getIGMIntegrityApplyInfoGuid());
			if(applyInfo != null && !StringUtils.isEmpty(applyInfo.getCompanyWellInfo())) {
				CompanyPoorInfoEntuty cpiea = (CompanyPoorInfoEntuty) XMLUtil.convertXmlStrToObject(CompanyPoorInfoEntuty.class, applyInfo.getCompanyPoorInfo());
				if(!StringUtils.isEmpty(cpie.getMaterials())) {
					if(!cpiea.getMaterials().equals(cpie.getMaterials())) {
						cpie.setMaterials(null);
					}
				}else {
					cpie.setMaterials(null);
				}
			}else {
				cpie.setMaterials(null);
			}
		}
		String selectScore = cpie.getPenaltyScores();
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
		igmai.setGuid(cpie.getIGMIntegrityApplyInfoGuid());
		cpie.setIGMIntegrityApplyInfoGuid(null);
		igmai.setName(cpie.getCompanyName());
		igmai.setDescription(cpie.getBehaviorDescription());
		if(cpie.getSaveOrReport().equals("保存")) {
    		igmai.setState("未上报");
    		cpie.setReportDate(null);
    		igmai.setReportDate(null);
    	}else if(cpie.getSaveOrReport().equals("上报")) {
    		igmai.setState("已上报");
    		cpie.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    		igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	}
		StandardEntity se = integrityInformationAddMapper.selectStandardEntityByGuid(cpie.getBehaviorCode());
		cpie.setStandard(se);
		cpie.setSaveOrReport(null);
		cpie.setInSource("手动添加");
		if("无上限".equals(MaxScores)) {
			cpie.setPenaltyScores(selectScore);
		}else {
			if(Double.parseDouble(cpie.getPointsDeducted()) < Double.parseDouble(se.getMaxScores())) {
	    		if((Double.parseDouble(cpie.getPointsDeducted()) + Double.parseDouble(selectScore)) < Double.parseDouble(se.getMaxScores())) {
	    			cpie.setPenaltyScores(selectScore);
	    		}else if((Double.parseDouble(cpie.getPointsDeducted()) + Double.parseDouble(selectScore)) > Double.parseDouble(se.getMaxScores())) {
	    			cpie.setPenaltyScores(String.valueOf(Double.parseDouble(se.getMaxScores()) - Double.parseDouble(cpie.getPointsDeducted())));
	    		}
	    	}else if(Double.parseDouble(cpie.getPointsDeducted()) >= Double.parseDouble(se.getMaxScores())) {
	    		cpie.setPenaltyScores("0");
	    	}
		}
		igmai.setCompanyPoorInfo(XMLUtil.convertToXml(cpie));
    	return integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
	}

	@Override
	public List<IGMIntegrityApplyInfo> selectPeopleGoodIGMIntegrityApplyInfoList(IGMIntegrityApplyInfo igmai) {
		igmai.setApplyType("人员良好");
		SysUser currentUser = ShiroUtils.getSysUser();
		if(!currentUser.getLoginName().equals("admin") && !currentUser.getLoginName().trim().equals("lingshui")) {
			igmai.setOperLoginName(currentUser.getLoginName());
		}
		List<IGMIntegrityApplyInfo> igmaiList = integrityInformationAddMapper.selectIGMIntegrityApplyInfoList(igmai);
		if(!StringUtils.isEmpty(igmaiList)) {
			for(IGMIntegrityApplyInfo igmiai:igmaiList) {
				PersonalWellInfoEntity pwie = (PersonalWellInfoEntity) XMLUtil.convertXmlStrToObject(PersonalWellInfoEntity.class, igmiai.getPersonalWellInfo());
				if(!StringUtils.isEmpty(pwie.getGuid())) {
					IGMPersonalWellInfo igmpwi = integrityInformationMapper.selectIGMPersonalWellInfoByGuid(pwie.getGuid());
					if(igmpwi!=null) {
						pwie.setUndoApplyDate(igmpwi.getUndoApplyDate());
					}
				}
				igmiai.setPersonalWellInfoEntity(pwie);
			}
		}
		return igmaiList;
	}

	@Override
	public String sumEnterBadAddedScores(IGMCompanyPoorInfo igmcpi) {
		String pointsAdded = integrityInformationAddMapper.sumEnterBadAddedScores(igmcpi);
		if(StringUtils.isEmpty(pointsAdded)) {
			pointsAdded = "0";
		}
		return pointsAdded;
	}

	@Override
	public String sumPeopleGoodAddedScores(IGMPersonalWellInfo igmpwi) {
		String pointsAdded = integrityInformationAddMapper.sumPeopleGoodAddedScores(igmpwi);
		if(StringUtils.isEmpty(pointsAdded)) {
			pointsAdded = "0";
		}
		return pointsAdded;
	}

	@Override
	public int personGoodBehaviorSaveAndReport(PersonalWellInfoEntity pwie,String MaxScores) {
		String selectScore = pwie.getScore();
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
    	igmai.setGuid(IdUtil.randomUUID());
    	igmai.setName(pwie.getPersonName());
    	igmai.setDescription(pwie.getBehaviorDescription());
    	igmai.setApplyType("人员良好");
    	igmai.setArea("陵水县");
    	SysUser currentUser = ShiroUtils.getSysUser();
    	igmai.setOperLoginName(currentUser.getLoginName());
    	igmai.setOperName(currentUser.getUserName());
    	igmai.setOperUnitGuid(String.valueOf(currentUser.getDeptId()));
    	igmai.setCompanyWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setCompanyPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setPersonnalPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	igmai.setApplyWay("登记");
    	if(pwie.getSaveOrReport().equals("保存")) {
    		igmai.setState("未上报");
    	}else if(pwie.getSaveOrReport().equals("上报")) {
    		igmai.setState("已上报");
    		igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	}
    	StandardEntity se = integrityInformationAddMapper.selectStandardEntityByGuid(pwie.getBehaviorCode());
    	pwie.setStandard(se);
    	pwie.setGuid(IdUtil.randomUUID());
    	pwie.setRegPerson(currentUser.getUserName());
    	pwie.setOwnerGuid(currentUser.getLoginName());
    	pwie.setRegDepartment(currentUser.getDept().getDeptName());
    	pwie.setRegDepartmentGuid(String.valueOf(currentUser.getDeptId()));
    	pwie.setSaveOrReport(null);
    	if("无上限".equals(MaxScores)) {
    		pwie.setScore(selectScore);
    	}else {
    		if(Double.parseDouble(pwie.getPointsAdded()) < Double.parseDouble(se.getMaxScores())) {
        		if((Double.parseDouble(pwie.getPointsAdded()) + Double.parseDouble(selectScore)) < Double.parseDouble(se.getMaxScores())) {
        			pwie.setScore(selectScore);
        		}else if((Double.parseDouble(pwie.getPointsAdded()) + Double.parseDouble(selectScore)) > Double.parseDouble(se.getMaxScores())) {
        			pwie.setScore(String.valueOf(Double.parseDouble(se.getMaxScores()) - Double.parseDouble(pwie.getPointsAdded())));
        		}
        	}else if(Double.parseDouble(pwie.getPointsAdded()) >= Double.parseDouble(se.getMaxScores())) {
        		pwie.setScore("0");
        	}
    	}
    	pwie.setInSource("手动添加");
    	igmai.setPersonalWellInfo(XMLUtil.convertToXml(pwie));
		return integrityInformationAddMapper.insertIGMIntegrityApplyInfo(igmai);
	}

	@Override
	public int updatepersonsGoodBehavior(PersonalWellInfoEntity pwie, int type,String MaxScores) {
		if(type == 1) {
			IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(pwie.getIGMIntegrityApplyInfoGuid());
			if(applyInfo != null && !StringUtils.isEmpty(applyInfo.getPersonalWellInfo())) {
				PersonalWellInfoEntity pwiea = (PersonalWellInfoEntity) XMLUtil.convertXmlStrToObject(PersonalWellInfoEntity.class, applyInfo.getPersonalWellInfo());
				if(!StringUtils.isEmpty(pwiea.getMaterials())) {
					if(!pwiea.getMaterials().equals(pwie.getMaterials())) {
						pwie.setMaterials(null);
					}
				}else {
					pwie.setMaterials(null);
				}
			}else {
				pwie.setMaterials(null);
			}
		}
		String selectScore = pwie.getScore();
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
		igmai.setGuid(pwie.getIGMIntegrityApplyInfoGuid());
		pwie.setIGMIntegrityApplyInfoGuid(null);
		igmai.setName(pwie.getPersonName());
		igmai.setDescription(pwie.getBehaviorDescription());
		if(pwie.getSaveOrReport().equals("保存")) {
    		igmai.setState("未上报");
    		igmai.setReportDate(null);
    	}else if(pwie.getSaveOrReport().equals("上报")) {
    		igmai.setState("已上报");
    		igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	}
		StandardEntity se = integrityInformationAddMapper.selectStandardEntityByGuid(pwie.getBehaviorCode());
		pwie.setStandard(se);
		pwie.setSaveOrReport(null);
		if("无上限".equals(MaxScores)) {
			pwie.setScore(selectScore);
		}else {
			if(Double.parseDouble(pwie.getPointsAdded()) < Double.parseDouble(se.getMaxScores())) {
	    		if((Double.parseDouble(pwie.getPointsAdded()) + Double.parseDouble(selectScore)) < Double.parseDouble(se.getMaxScores())) {
	    			pwie.setScore(selectScore);
	    		}else if((Double.parseDouble(pwie.getPointsAdded()) + Double.parseDouble(selectScore)) > Double.parseDouble(se.getMaxScores())) {
	    			pwie.setScore(String.valueOf(Double.parseDouble(se.getMaxScores()) - Double.parseDouble(pwie.getPointsAdded())));
	    		}
	    	}else if(Double.parseDouble(pwie.getPointsAdded()) >= Double.parseDouble(se.getMaxScores())) {
	    		pwie.setScore("0");
	    	}
		}
		pwie.setInSource("手动添加");
    	igmai.setPersonalWellInfo(XMLUtil.convertToXml(pwie));
		return integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
	}

	@Override
	public List<IGMIntegrityApplyInfo> selectPeopleBadIGMIntegrityApplyInfoList(IGMIntegrityApplyInfo igmai) {
		igmai.setApplyType("人员不良");
		SysUser currentUser = ShiroUtils.getSysUser();
		if(!currentUser.getLoginName().equals("admin") && !currentUser.getLoginName().trim().equals("lingshui")) {
			igmai.setOperLoginName(currentUser.getLoginName());
		}
		List<IGMIntegrityApplyInfo> igmaiList = integrityInformationAddMapper.selectIGMIntegrityApplyInfoList(igmai);
		if(!StringUtils.isEmpty(igmaiList)) {
			for(IGMIntegrityApplyInfo igmiai:igmaiList) {
				PersonalPoorInfoEntity ppie = (PersonalPoorInfoEntity) XMLUtil.convertXmlStrToObject(PersonalPoorInfoEntity.class, igmiai.getPersonnalPoorInfo());
				if(!StringUtils.isEmpty(ppie.getGuid())) {
					IGMPersonalPoorInfo igmppi = integrityInformationMapper.selectIGMPersonalPoorInfoByGuid(ppie.getGuid());
					if(igmppi != null) {
						ppie.setUndoApplyDate(igmppi.getUndoApplyDate());
					}
				}
				igmiai.setPersonnalPoorInfoEntity(ppie);
			}
		}
		return igmaiList;
	}

	@Override
	public String sumPeopleBadAddedScores(IGMPersonalPoorInfo igmppi) {
		String pointsAdded = integrityInformationAddMapper.sumPeopleBadAddedScores(igmppi);
		if(StringUtils.isEmpty(pointsAdded)) {
			pointsAdded = "0";
		}
		return pointsAdded;
	}

	@Override
	public int personBadBehaviorSaveAndReport(PersonalPoorInfoEntity ppie,String MaxScores) {
		String selectScore = ppie.getPenaltyScores();
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
		igmai.setGuid(IdUtil.randomUUID());
    	igmai.setName(ppie.getPersonName());
    	igmai.setDescription(ppie.getBehaviorDescription());
    	igmai.setApplyType("人员不良");
    	igmai.setArea("陵水县");
    	SysUser currentUser = ShiroUtils.getSysUser();
    	igmai.setOperLoginName(currentUser.getLoginName());
    	igmai.setOperName(currentUser.getUserName());
    	igmai.setOperUnitGuid(String.valueOf(currentUser.getDeptId()));
    	igmai.setCompanyWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setCompanyPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setPersonalWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
    	igmai.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	igmai.setApplyWay("登记");
    	if(ppie.getSaveOrReport().equals("保存")) {
    		igmai.setState("未上报");
    	}else if(ppie.getSaveOrReport().equals("上报")) {
    		igmai.setState("已上报");
    		ppie.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    		igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	}
    	StandardEntity se = integrityInformationAddMapper.selectStandardEntityByGuid(ppie.getBehaviorCode());
    	ppie.setStandard(se);
    	ppie.setGuid(IdUtil.randomUUID());
    	ppie.setRegisterName(currentUser.getUserName());
    	ppie.setLoginId(currentUser.getLoginName());
    	ppie.setRegisterDept(currentUser.getDept().getDeptName());
    	ppie.setRegisterDeptGuid(String.valueOf(currentUser.getDeptId()));
    	ppie.setSaveOrReport(null);
    	if("无上限".equals(MaxScores)) {
    		ppie.setPenaltyScores(selectScore);
    	}else {
    		if(Double.parseDouble(ppie.getPointsDeducted()) < Double.parseDouble(se.getMaxScores())) {
        		if((Double.parseDouble(ppie.getPointsDeducted()) + Double.parseDouble(selectScore)) < Double.parseDouble(se.getMaxScores())) {
        			ppie.setPenaltyScores(selectScore);
        		}else if((Double.parseDouble(ppie.getPointsDeducted()) + Double.parseDouble(selectScore)) > Double.parseDouble(se.getMaxScores())) {
        			ppie.setPenaltyScores(String.valueOf(Double.parseDouble(se.getMaxScores()) - Double.parseDouble(ppie.getPointsDeducted())));
        		}
        	}else if(Double.parseDouble(ppie.getPointsDeducted()) >= Double.parseDouble(se.getMaxScores())) {
        		ppie.setPenaltyScores("0");
        	}
    	}
    	ppie.setInSource("手动添加");
    	igmai.setPersonnalPoorInfo(XMLUtil.convertToXml(ppie));
    	return integrityInformationAddMapper.insertIGMIntegrityApplyInfo(igmai);
	}

	
	@Override
	public int updatePeopleBadBehavior(PersonalPoorInfoEntity ppie, int type, String MaxScores) {
		if(type == 1) {
			IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(ppie.getIGMIntegrityApplyInfoGuid());
			if(applyInfo != null && !StringUtils.isEmpty(applyInfo.getPersonnalPoorInfo())) {
				PersonalPoorInfoEntity ppiea = (PersonalPoorInfoEntity) XMLUtil.convertXmlStrToObject(PersonalPoorInfoEntity.class, applyInfo.getPersonnalPoorInfo());
				if(!StringUtils.isEmpty(ppie.getMaterials())) {
					if(!ppiea.getMaterials().equals(ppie.getMaterials())) {
						ppie.setMaterials(null);
					}
				}else {
					ppie.setMaterials(null);
				}
			}else {
				ppie.setMaterials(null);
			}
		}
		String selectScore = ppie.getPenaltyScores();
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
		igmai.setGuid(ppie.getIGMIntegrityApplyInfoGuid());
		ppie.setIGMIntegrityApplyInfoGuid(null);
		igmai.setName(ppie.getPersonName());
		igmai.setDescription(ppie.getBehaviorDescription());
		if(ppie.getSaveOrReport().equals("保存")) {
    		igmai.setState("未上报");
    		ppie.setReportDate(null);
    		igmai.setReportDate(null);
    	}else if(ppie.getSaveOrReport().equals("上报")) {
    		igmai.setState("已上报");
    		ppie.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    		igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
    	}
		StandardEntity se = integrityInformationAddMapper.selectStandardEntityByGuid(ppie.getBehaviorCode());
		ppie.setStandard(se);
		ppie.setSaveOrReport(null);
		ppie.setInSource("手动添加");
		if("无上限".equals(MaxScores)) {
			ppie.setPenaltyScores(selectScore);
		}else {
			if(Double.parseDouble(ppie.getPointsDeducted()) < Double.parseDouble(se.getMaxScores())) {
	    		if((Double.parseDouble(ppie.getPointsDeducted()) + Double.parseDouble(selectScore)) < Double.parseDouble(se.getMaxScores())) {
	    			ppie.setPenaltyScores(selectScore);
	    		}else if((Double.parseDouble(ppie.getPointsDeducted()) + Double.parseDouble(selectScore)) > Double.parseDouble(se.getMaxScores())) {
	    			ppie.setPenaltyScores(String.valueOf(Double.parseDouble(se.getMaxScores()) - Double.parseDouble(ppie.getPointsDeducted())));
	    		}
	    	}else if(Double.parseDouble(ppie.getPointsDeducted()) >= Double.parseDouble(se.getMaxScores())) {
	    		ppie.setPenaltyScores("0");
	    	}
		}
		igmai.setPersonnalPoorInfo(XMLUtil.convertToXml(ppie));
    	return integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
	}

	@Override
	@Transactional
	public int enterprisesGoodBehaviorApprove(CompanyWellInfoEntity cwie, String reasonContent) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(cwie.getIGMIntegrityApplyInfoGuid());
		CompanyWellInfoEntity companyWell = (CompanyWellInfoEntity) XMLUtil.convertXmlStrToObject(CompanyWellInfoEntity.class, applyInfo.getCompanyWellInfo());
		SysUser currentUser = ShiroUtils.getSysUser();
		if(companyWell!=null) {
			if("通过".equals(cwie.getSaveOrReport())) {
				applyInfo.setPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				applyInfo.setState("审核通过");
				companyWell.setState("正常");
				companyWell.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				companyWell.setLNPublishStartDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				IGMBehavioStandard igmbs = integrityInformationAddMapper.selectIGMBehavioStandardByGuid(companyWell.getBehaviorCode());
				Date newDate = DateUtil.offsetMonth(new Date(), Integer.parseInt(igmbs.getValid()));
				Date date = DateUtil.offsetDay(newDate, -1);
				companyWell.setLNPublishEndDate(DateUtil.format(date, DatePattern.NORM_DATETIME_MS_PATTERN));
				applyInfo.setCompanyWellInfo(XMLUtil.convertToXml(companyWell));
				int ai = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(applyInfo);
				IGMAuditRecord igmar = new IGMAuditRecord();
				igmar.setGuid(IdUtil.randomUUID());
				igmar.setDataGuid(cwie.getIGMIntegrityApplyInfoGuid());
				igmar.setType("审核");
				igmar.setConclusion("通过");
				igmar.setOpinion(reasonContent);
				igmar.setOperLoginName(currentUser.getLoginName());
				igmar.setOperName(currentUser.getUserName());
				igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				companyWell.setUndo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket />");
				int igmCompanyWell = integrityInformationAddMapper.insertIGMCompanyWellInfo(companyWell);
				int auditRecord = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
				return ai+igmCompanyWell+auditRecord;
			}else {
				applyInfo.setState("审核退回");
				int ai = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(applyInfo);
				IGMAuditRecord igmar = new IGMAuditRecord();
				igmar.setGuid(IdUtil.randomUUID());
				igmar.setDataGuid(cwie.getIGMIntegrityApplyInfoGuid());
				igmar.setType("审核");
				igmar.setConclusion("不通过");
				igmar.setOpinion(reasonContent);
				igmar.setOperLoginName(currentUser.getLoginName());
				igmar.setOperName(currentUser.getUserName());
				igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				int auditRecord = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
				return ai+auditRecord;
			}
		}
		return 0;
	}

	@Override
	@Transactional
	public int enterprisesBadBehaviorApprove(CompanyPoorInfoEntuty cpie, String reasonContent) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(cpie.getIGMIntegrityApplyInfoGuid());
		CompanyPoorInfoEntuty companyPoor = (CompanyPoorInfoEntuty) XMLUtil.convertXmlStrToObject(CompanyPoorInfoEntuty.class, applyInfo.getCompanyPoorInfo());
		SysUser currentUser = ShiroUtils.getSysUser();
		if(companyPoor!=null) {
			if("通过".equals(cpie.getSaveOrReport())) {
				applyInfo.setPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				applyInfo.setState("审核通过");
				companyPoor.setIsReported("正常");
				companyPoor.setRegisterDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				companyPoor.setPublishStartDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				IGMBehavioStandard igmbs = integrityInformationAddMapper.selectIGMBehavioStandardByGuid(companyPoor.getBehaviorCode());
				Date newDate = DateUtil.offsetMonth(new Date(), Integer.parseInt(igmbs.getValid()));
				Date date = DateUtil.offsetDay(newDate, -1);
				companyPoor.setPublishEndDate(DateUtil.format(date, DatePattern.NORM_DATETIME_MS_PATTERN));
				applyInfo.setCompanyPoorInfo(XMLUtil.convertToXml(companyPoor));
				int ai = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(applyInfo);
				IGMAuditRecord igmar = new IGMAuditRecord();
				igmar.setGuid(IdUtil.randomUUID());
				igmar.setDataGuid(cpie.getIGMIntegrityApplyInfoGuid());
				igmar.setType("审核");
				igmar.setConclusion("通过");
				igmar.setOpinion(reasonContent);
				igmar.setOperLoginName(currentUser.getLoginName());
				igmar.setOperName(currentUser.getUserName());
				igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				companyPoor.setUndo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket />");
				int igmCompanyPoor = integrityInformationAddMapper.insertIGMCompanyPoorInfo(companyPoor);
				int auditRecord = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
				return ai+igmCompanyPoor+auditRecord;
			}else {
				applyInfo.setState("审核退回");
				int ai = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(applyInfo);
				IGMAuditRecord igmar = new IGMAuditRecord();
				igmar.setGuid(IdUtil.randomUUID());
				igmar.setDataGuid(cpie.getIGMIntegrityApplyInfoGuid());
				igmar.setType("审核");
				igmar.setConclusion("不通过");
				igmar.setOpinion(reasonContent);
				igmar.setOperLoginName(currentUser.getLoginName());
				igmar.setOperName(currentUser.getUserName());
				igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				int auditRecord = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
				return ai+auditRecord;
			}
		}
		return 0;
	}

	@Override
	@Transactional
	public int peopleGoodBehaviorApprove(PersonalWellInfoEntity pwie, String reasonContent) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(pwie.getIGMIntegrityApplyInfoGuid());
		PersonalWellInfoEntity personalWell = (PersonalWellInfoEntity) XMLUtil.convertXmlStrToObject(PersonalWellInfoEntity.class, applyInfo.getPersonalWellInfo());
		SysUser currentUser = ShiroUtils.getSysUser();
		if(personalWell!=null) {
			if("通过".equals(pwie.getSaveOrReport())) {
				applyInfo.setPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				applyInfo.setState("审核通过");
				personalWell.setState("正常");
				personalWell.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				personalWell.setLNPublishStartDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				IGMBehavioStandard igmbs = integrityInformationAddMapper.selectIGMBehavioStandardByGuid(personalWell.getBehaviorCode());
				Date newDate = DateUtil.offsetMonth(new Date(), Integer.parseInt(igmbs.getValid()));
				Date date = DateUtil.offsetDay(newDate, -1);
				personalWell.setLNPublishEndDate(DateUtil.format(date, DatePattern.NORM_DATETIME_MS_PATTERN));
				applyInfo.setPersonalWellInfo(XMLUtil.convertToXml(personalWell));
				int ai = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(applyInfo);
				IGMAuditRecord igmar = new IGMAuditRecord();
				igmar.setGuid(IdUtil.randomUUID());
				igmar.setDataGuid(pwie.getIGMIntegrityApplyInfoGuid());
				igmar.setType("审核");
				igmar.setConclusion("通过");
				igmar.setOpinion(reasonContent);
				igmar.setOperLoginName(currentUser.getLoginName());
				igmar.setOperName(currentUser.getUserName());
				igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				personalWell.setUndo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket />");
				int igmPersonalWell = integrityInformationAddMapper.insertIGMPersonalWellInfo(personalWell);
				int auditRecord = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
				return ai+igmPersonalWell+auditRecord;
			}else {
				applyInfo.setState("审核退回");
				int ai = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(applyInfo);
				IGMAuditRecord igmar = new IGMAuditRecord();
				igmar.setGuid(IdUtil.randomUUID());
				igmar.setDataGuid(pwie.getIGMIntegrityApplyInfoGuid());
				igmar.setType("审核");
				igmar.setConclusion("不通过");
				igmar.setOpinion(reasonContent);
				igmar.setOperLoginName(currentUser.getLoginName());
				igmar.setOperName(currentUser.getUserName());
				igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				int auditRecord = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
				return ai+auditRecord;
			}
		}
		return 0;
	}

	@Override
	@Transactional
	public int peopleBadBehaviorApprove(PersonalPoorInfoEntity ppie, String reasonContent) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(ppie.getIGMIntegrityApplyInfoGuid());
		PersonalPoorInfoEntity personalPoor = (PersonalPoorInfoEntity) XMLUtil.convertXmlStrToObject(PersonalPoorInfoEntity.class, applyInfo.getPersonnalPoorInfo());
		SysUser currentUser = ShiroUtils.getSysUser();
		if(personalPoor!=null) {
			if("通过".equals(ppie.getSaveOrReport())) {
				applyInfo.setPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				applyInfo.setState("审核通过");
				personalPoor.setIsReported("正常");
				personalPoor.setRegisterDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				personalPoor.setPublishStartDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				IGMBehavioStandard igmbs = integrityInformationAddMapper.selectIGMBehavioStandardByGuid(personalPoor.getBehaviorCode());
				Date newDate = DateUtil.offsetMonth(new Date(), Integer.parseInt(igmbs.getValid()));
				Date date = DateUtil.offsetDay(newDate, -1);
				personalPoor.setPublishEndDate(DateUtil.format(date, DatePattern.NORM_DATETIME_MS_PATTERN));
				applyInfo.setPersonnalPoorInfo(XMLUtil.convertToXml(personalPoor));
				int ai = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(applyInfo);
				IGMAuditRecord igmar = new IGMAuditRecord();
				igmar.setGuid(IdUtil.randomUUID());
				igmar.setDataGuid(ppie.getIGMIntegrityApplyInfoGuid());
				igmar.setType("审核");
				igmar.setConclusion("通过");
				igmar.setOpinion(reasonContent);
				igmar.setOperLoginName(currentUser.getLoginName());
				igmar.setOperName(currentUser.getUserName());
				igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				personalPoor.setUndo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket />");
				int igmPersonalPoor = integrityInformationAddMapper.insertIGMPersonalPoorInfo(personalPoor);
				int auditRecord = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
				return ai+igmPersonalPoor+auditRecord;
			}else {
				applyInfo.setState("审核退回");
				int ai = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(applyInfo);
				IGMAuditRecord igmar = new IGMAuditRecord();
				igmar.setGuid(IdUtil.randomUUID());
				igmar.setDataGuid(ppie.getIGMIntegrityApplyInfoGuid());
				igmar.setType("审核");
				igmar.setConclusion("不通过");
				igmar.setOpinion(reasonContent);
				igmar.setOperLoginName(currentUser.getLoginName());
				igmar.setOperName(currentUser.getUserName());
				igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
				int auditRecord = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
				return ai+auditRecord;
			}
		}
		return 0;
	}

	@Override
	public int insertIGMPersonalPoorInfo(PersonalPoorInfoEntity ppie) {
		int i = integrityInformationAddMapper.insertIGMPersonalPoorInfo(ppie);
		return i;
	}

	@Override
	@Transactional
	public int enterprisesGoodBehaviorUndoSaveAndReport(CompanyWellInfoEntity cwie) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(cwie.getIGMIntegrityApplyInfoGuid());
		IGMIntegrityApplyInfo igmiai = new IGMIntegrityApplyInfo();
		igmiai.setGuid(IdUtil.randomUUID());
		igmiai.setName(applyInfo.getName());
		igmiai.setDescription(applyInfo.getDescription());
		igmiai.setApplyType(applyInfo.getApplyType());
		igmiai.setArea(applyInfo.getArea());
		if("保存并上报".equals(cwie.getSaveOrReport())) {
			igmiai.setState("已上报");
			igmiai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		}else {
			igmiai.setState("未上报");
		}
		SysUser currentUser = ShiroUtils.getSysUser();
		igmiai.setOperLoginName(currentUser.getLoginName());
		igmiai.setOperName(currentUser.getUserName());
		igmiai.setOperUnitGuid(String.valueOf(currentUser.getDeptId()));
		CompanyWellInfoEntity cwea = (CompanyWellInfoEntity) XMLUtil.convertXmlStrToObject(CompanyWellInfoEntity.class, applyInfo.getCompanyWellInfo());
		cwea.setUndoReason(cwie.getUndoReason());
		igmiai.setCompanyWellInfo(XMLUtil.convertToXml(cwea));
		igmiai.setCompanyPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setPersonalWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setPersonnalPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		igmiai.setApplyWay("撤销");
		igmiai.setDataGuid(cwie.getGuid());
		CompanyWellInfoEntity companyWell = new CompanyWellInfoEntity();
		companyWell.setUndoReason(cwie.getUndoReason());
		companyWell.setUndoOperLoginName(currentUser.getLoginName());
		companyWell.setUndoOperName(currentUser.getUserName());
		companyWell.setUndoApplyDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		companyWell.setGuid(cwie.getGuid());
		int a = integrityInformationAddMapper.insertIGMIntegrityApplyInfo(igmiai);
		int b = integrityInformationAddMapper.updateIGMCompanyWellInfo(companyWell);
		return a+b;
	}

	@Override
	@Transactional
	public int enterprisesGoodBehaviorUndoSaveAndReportUpdate(CompanyWellInfoEntity cwie) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(cwie.getIGMIntegrityApplyInfoGuid());
		CompanyWellInfoEntity cwea = (CompanyWellInfoEntity) XMLUtil.convertXmlStrToObject(CompanyWellInfoEntity.class, applyInfo.getCompanyWellInfo());
		cwea.setUndoReason(cwie.getUndoReason());
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
		igmai.setGuid(cwie.getIGMIntegrityApplyInfoGuid());
		igmai.setCompanyWellInfo(XMLUtil.convertToXml(cwea));
		CompanyWellInfoEntity companyWell = new CompanyWellInfoEntity();
		companyWell.setGuid(cwie.getGuid());
		companyWell.setUndoReason(cwie.getUndoReason());
		if("保存并上报".equals(cwie.getSaveOrReport())) {
			igmai.setState("已上报");
			igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		}else {
			igmai.setState("未上报");
		}
		int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
		int b = integrityInformationAddMapper.updateIGMCompanyWellInfo(companyWell);
		return a+b;
	}

	@Override
	@Transactional
	public int enterprisesGoodBehaviorUndoApprove(CompanyWellInfoEntity cwie, String reasonContent) {
		SysUser currentUser = ShiroUtils.getSysUser();
		if("通过".equals(cwie.getSaveOrReport())) {
			IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
			igmai.setGuid(cwie.getIGMIntegrityApplyInfoGuid());
			igmai.setState("审核通过");
			igmai.setPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
			CompanyWellInfoEntity companyWellInfo = new CompanyWellInfoEntity();
			companyWellInfo.setUndoPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			companyWellInfo.setGuid(cwie.getGuid());
			companyWellInfo.setState("已撤销");
			int b = integrityInformationAddMapper.updateIGMCompanyWellInfo(companyWellInfo);
			IGMAuditRecord igmar = new IGMAuditRecord();
			igmar.setGuid(IdUtil.randomUUID());
			igmar.setDataGuid(cwie.getIGMIntegrityApplyInfoGuid());
			igmar.setType("行为信息撤销");
			igmar.setConclusion("通过");
			igmar.setOpinion(reasonContent);
			igmar.setOperLoginName(currentUser.getLoginName());
			igmar.setOperName(currentUser.getUserName());
			igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int c = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
			return a+b+c;
		}else if("不通过".equals(cwie.getSaveOrReport())) {
			IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
			igmai.setGuid(cwie.getIGMIntegrityApplyInfoGuid());
			igmai.setState("审核退回");
//			IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(cwie.getIGMIntegrityApplyInfoGuid());
//			CompanyWellInfoEntity companyWellInfo = (CompanyWellInfoEntity) XMLUtil.convertXmlStrToObject(CompanyWellInfoEntity.class, applyInfo.getCompanyWellInfo());
//			if(!StringUtils.isEmpty(companyWellInfo.getUndoReason())) {
//				companyWellInfo.setUndoReason(null);
//				igmai.setCompanyWellInfo(XMLUtil.convertToXml(companyWellInfo));
//			}
			int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
			int b = integrityInformationAddMapper.updateIGMCompanyWellInfoNoPass(cwie.getGuid());
			IGMAuditRecord igmar = new IGMAuditRecord();
			igmar.setGuid(IdUtil.randomUUID());
			igmar.setDataGuid(cwie.getIGMIntegrityApplyInfoGuid());
			igmar.setType("行为信息撤销");
			igmar.setConclusion("不通过");
			igmar.setOpinion(reasonContent);
			igmar.setOperLoginName(currentUser.getLoginName());
			igmar.setOperName(currentUser.getUserName());
			igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int c = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
			return a+b+c;
		}
		return 0;
	}

	@Override
	public List<String> selectIGMCompanyWellInfoByDateadd(String organCode) {
		// TODO Auto-generated method stub
		return integrityInformationAddMapper.selectIGMCompanyWellInfoByDateadd(organCode);
	}

	@Override
	public boolean judgeQualificationsUndo(String organCode, String qualif) {
		List<String> strList = integrityInformationAddMapper.selectIGMCompanyWellInfoByDateadd(organCode);
		if(CollUtil.contains(strList, qualif)) {
			return true;
		}
		return false;
	}

	@Override
	public int enterprisesBadBehaviorUndoSaveAndReport(CompanyPoorInfoEntuty cpie) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(cpie.getIGMIntegrityApplyInfoGuid());
		IGMIntegrityApplyInfo igmiai = new IGMIntegrityApplyInfo();
		igmiai.setGuid(IdUtil.randomUUID());
		igmiai.setName(applyInfo.getName());
		igmiai.setDescription(applyInfo.getDescription());
		igmiai.setApplyType(applyInfo.getApplyType());
		igmiai.setArea(applyInfo.getArea());
		if("保存并上报".equals(cpie.getSaveOrReport())) {
			igmiai.setState("已上报");
			igmiai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		}else {
			igmiai.setState("未上报");
		}
		SysUser currentUser = ShiroUtils.getSysUser();
		igmiai.setOperLoginName(currentUser.getLoginName());
		igmiai.setOperName(currentUser.getUserName());
		igmiai.setOperUnitGuid(String.valueOf(currentUser.getDeptId()));
		CompanyPoorInfoEntuty cpiea = (CompanyPoorInfoEntuty) XMLUtil.convertXmlStrToObject(CompanyPoorInfoEntuty.class, applyInfo.getCompanyPoorInfo());
		cpiea.setUndoReason(cpie.getUndoReason());
		igmiai.setCompanyPoorInfo(XMLUtil.convertToXml(cpiea));
		igmiai.setCompanyWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setPersonalWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setPersonnalPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		igmiai.setApplyWay("撤销");
		igmiai.setDataGuid(cpie.getGuid());
		CompanyPoorInfoEntuty companyPoor = new CompanyPoorInfoEntuty();
		companyPoor.setUndoReason(cpie.getUndoReason());
		companyPoor.setUndoOperLoginName(currentUser.getLoginName());
		companyPoor.setUndoOperName(currentUser.getUserName());
		companyPoor.setUndoApplyDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		companyPoor.setGuid(cpie.getGuid());
		int a = integrityInformationAddMapper.insertIGMIntegrityApplyInfo(igmiai);
		int b = integrityInformationAddMapper.updateIGMCompanyPoorInfo(companyPoor);
		return a+b;
	}

	@Override
	@Transactional
	public int enterprisesBadBehaviorUndoSaveAndReportUpdate(CompanyPoorInfoEntuty cpie) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(cpie.getIGMIntegrityApplyInfoGuid());
		CompanyPoorInfoEntuty cpiea = (CompanyPoorInfoEntuty) XMLUtil.convertXmlStrToObject(CompanyPoorInfoEntuty.class, applyInfo.getCompanyPoorInfo());
		cpiea.setUndoReason(cpie.getUndoReason());
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
		igmai.setGuid(cpie.getIGMIntegrityApplyInfoGuid());
		igmai.setCompanyPoorInfo(XMLUtil.convertToXml(cpiea));
		CompanyPoorInfoEntuty companyPoor = new CompanyPoorInfoEntuty();
		companyPoor.setGuid(cpie.getGuid());
		companyPoor.setUndoReason(cpie.getUndoReason());
		if("保存并上报".equals(cpie.getSaveOrReport())) {
			igmai.setState("已上报");
			igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		}else {
			igmai.setState("未上报");
		}
		int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
		int b = integrityInformationAddMapper.updateIGMCompanyPoorInfo(companyPoor);
		return a+b;
	}

	@Override
	@Transactional
	public int enterprisesBadBehaviorUndoApprove(CompanyPoorInfoEntuty cpie, String reasonContent) {
		SysUser currentUser = ShiroUtils.getSysUser();
		if("通过".equals(cpie.getSaveOrReport())) {
			IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
			igmai.setGuid(cpie.getIGMIntegrityApplyInfoGuid());
			igmai.setState("审核通过");
			igmai.setPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
			CompanyPoorInfoEntuty companyPoorInfo = new CompanyPoorInfoEntuty();
			companyPoorInfo.setUndoPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			companyPoorInfo.setGuid(cpie.getGuid());
			companyPoorInfo.setIsReported("已撤销");
			int b = integrityInformationAddMapper.updateIGMCompanyPoorInfo(companyPoorInfo);
			IGMAuditRecord igmar = new IGMAuditRecord();
			igmar.setGuid(IdUtil.randomUUID());
			igmar.setDataGuid(cpie.getIGMIntegrityApplyInfoGuid());
			igmar.setType("行为信息撤销");
			igmar.setConclusion("通过");
			igmar.setOpinion(reasonContent);
			igmar.setOperLoginName(currentUser.getLoginName());
			igmar.setOperName(currentUser.getUserName());
			igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int c = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
			return a+b+c;
		}else if("不通过".equals(cpie.getSaveOrReport())) {
			IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
			igmai.setGuid(cpie.getIGMIntegrityApplyInfoGuid());
			igmai.setState("审核退回");
//			IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(cpie.getIGMIntegrityApplyInfoGuid());
//			CompanyPoorInfoEntuty companyPoorInfo = (CompanyPoorInfoEntuty) XMLUtil.convertXmlStrToObject(CompanyPoorInfoEntuty.class, applyInfo.getCompanyPoorInfo());
//			if(!StringUtils.isEmpty(companyPoorInfo.getUndoReason())) {
//				companyPoorInfo.setUndoReason(null);
//				igmai.setCompanyPoorInfo(XMLUtil.convertToXml(companyPoorInfo));
//			}
			int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
			int b = integrityInformationAddMapper.updateIGMCompanyPoorInfoNoPass(cpie.getGuid());
			IGMAuditRecord igmar = new IGMAuditRecord();
			igmar.setGuid(IdUtil.randomUUID());
			igmar.setDataGuid(cpie.getIGMIntegrityApplyInfoGuid());
			igmar.setType("行为信息撤销");
			igmar.setConclusion("不通过");
			igmar.setOpinion(reasonContent);
			igmar.setOperLoginName(currentUser.getLoginName());
			igmar.setOperName(currentUser.getUserName());
			igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int c = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
			return a+b+c;
		}
		return 0;
	}

	@Override
	public List<String> selectIGMCompanyPoorInfoByDateadd(String organCode) {
		// TODO Auto-generated method stub
		return integrityInformationAddMapper.selectIGMCompanyPoorInfoByDateadd(organCode);
	}

	@Override
	public boolean judgeQualificationsUndoPoor(String organCode, String qualif) {
		List<String> strList = integrityInformationAddMapper.selectIGMCompanyPoorInfoByDateadd(organCode);
		if(CollUtil.contains(strList, qualif)) {
			return true;
		}
		return false;
	}

	@Override
	@Transactional
	public int peopleGoodBehaviorUndoSaveAndReport(PersonalWellInfoEntity pwie) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(pwie.getIGMIntegrityApplyInfoGuid());
		IGMIntegrityApplyInfo igmiai = new IGMIntegrityApplyInfo();
		igmiai.setGuid(IdUtil.randomUUID());
		igmiai.setName(applyInfo.getName());
		igmiai.setDescription(applyInfo.getDescription());
		igmiai.setApplyType(applyInfo.getApplyType());
		igmiai.setArea(applyInfo.getArea());
		if("保存并上报".equals(pwie.getSaveOrReport())) {
			igmiai.setState("已上报");
			igmiai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		}else {
			igmiai.setState("未上报");
		}
		SysUser currentUser = ShiroUtils.getSysUser();
		igmiai.setOperLoginName(currentUser.getLoginName());
		igmiai.setOperName(currentUser.getUserName());
		igmiai.setOperUnitGuid(String.valueOf(currentUser.getDeptId()));
		PersonalWellInfoEntity pwiea = (PersonalWellInfoEntity) XMLUtil.convertXmlStrToObject(PersonalWellInfoEntity.class, applyInfo.getPersonalWellInfo());
		pwiea.setUndoReason(pwie.getUndoReason());
		igmiai.setPersonalWellInfo(XMLUtil.convertToXml(pwiea));
		igmiai.setCompanyWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setCompanyPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setPersonnalPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		igmiai.setApplyWay("撤销");
		igmiai.setDataGuid(pwie.getGuid());
		PersonalWellInfoEntity personalWell = new PersonalWellInfoEntity();
		personalWell.setUndoReason(pwie.getUndoReason());
		personalWell.setUndoOperLoginName(currentUser.getLoginName());
		personalWell.setUndoOperName(currentUser.getUserName());
		personalWell.setUndoApplyDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		personalWell.setGuid(pwie.getGuid());
		int a = integrityInformationAddMapper.insertIGMIntegrityApplyInfo(igmiai);
		int b = integrityInformationAddMapper.updateIGMPersonalWellInfo(personalWell);
		return a+b;
	}

	@Override
	@Transactional
	public int peopleGoodBehaviorUndoSaveAndReportUpdate(PersonalWellInfoEntity pwie) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(pwie.getIGMIntegrityApplyInfoGuid());
		PersonalWellInfoEntity pwiea = (PersonalWellInfoEntity) XMLUtil.convertXmlStrToObject(PersonalWellInfoEntity.class, applyInfo.getPersonalWellInfo());
		pwiea.setUndoReason(pwie.getUndoReason());
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
		igmai.setGuid(pwie.getIGMIntegrityApplyInfoGuid());
		igmai.setPersonalWellInfo(XMLUtil.convertToXml(pwiea));
		PersonalWellInfoEntity personalWell = new PersonalWellInfoEntity();
		personalWell.setGuid(pwie.getGuid());
		personalWell.setUndoReason(pwie.getUndoReason());
		if("保存并上报".equals(pwie.getSaveOrReport())) {
			igmai.setState("已上报");
			igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		}else {
			igmai.setState("未上报");
		}
		int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
		int b = integrityInformationAddMapper.updateIGMPersonalWellInfo(personalWell);
		return a+b;
	}
	

	@Override
	@Transactional
	public int peopleGoodBehaviorUndoApprove(PersonalWellInfoEntity pwie, String reasonContent) {
		SysUser currentUser = ShiroUtils.getSysUser();
		if("通过".equals(pwie.getSaveOrReport())) {
			IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
			igmai.setGuid(pwie.getIGMIntegrityApplyInfoGuid());
			igmai.setState("审核通过");
			igmai.setPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
			PersonalWellInfoEntity personalWellInfo = new PersonalWellInfoEntity();
			personalWellInfo.setUndoPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			personalWellInfo.setGuid(pwie.getGuid());
			personalWellInfo.setState("已撤销");
			int b = integrityInformationAddMapper.updateIGMPersonalWellInfo(personalWellInfo);
			IGMAuditRecord igmar = new IGMAuditRecord();
			igmar.setGuid(IdUtil.randomUUID());
			igmar.setDataGuid(pwie.getIGMIntegrityApplyInfoGuid());
			igmar.setType("行为信息撤销");
			igmar.setConclusion("通过");
			igmar.setOpinion(reasonContent);
			igmar.setOperLoginName(currentUser.getLoginName());
			igmar.setOperName(currentUser.getUserName());
			igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int c = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
			return a+b+c;
		}else if("不通过".equals(pwie.getSaveOrReport())) {
			IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
			igmai.setGuid(pwie.getIGMIntegrityApplyInfoGuid());
			igmai.setState("审核退回");
//			IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(pwie.getIGMIntegrityApplyInfoGuid());
//			PersonalWellInfoEntity personalWellInfo = (PersonalWellInfoEntity) XMLUtil.convertXmlStrToObject(PersonalWellInfoEntity.class, applyInfo.getPersonalWellInfo());
//			if(!StringUtils.isEmpty(personalWellInfo.getUndoReason())) {
//				personalWellInfo.setUndoReason(null);
//				igmai.setPersonalWellInfo(XMLUtil.convertToXml(personalWellInfo));
//			}
			int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
			int b = integrityInformationAddMapper.updateIGMPersonalWellInfoNoPass(pwie.getGuid());
			IGMAuditRecord igmar = new IGMAuditRecord();
			igmar.setGuid(IdUtil.randomUUID());
			igmar.setDataGuid(pwie.getIGMIntegrityApplyInfoGuid());
			igmar.setType("行为信息撤销");
			igmar.setConclusion("不通过");
			igmar.setOpinion(reasonContent);
			igmar.setOperLoginName(currentUser.getLoginName());
			igmar.setOperName(currentUser.getUserName());
			igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int c = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
			return a+b+c;
		}
		return 0;
	}

	@Override
	public List<String> selectIGMPersonalWellInfoByDateadd(String idcard) {
		// TODO Auto-generated method stub
		return integrityInformationAddMapper.selectIGMPersonalWellInfoByDateadd(idcard);
	}

	@Override
	public boolean judgeQualificationsUndoPeopleWell(String idcard, String qualif) {
		List<String> strList = integrityInformationAddMapper.selectIGMPersonalWellInfoByDateadd(idcard);
		if(CollUtil.contains(strList, qualif)) {
			return true;
		}
		return false;
	}

	@Override
	@Transactional
	public int peopleBadBehaviorUndoSaveAndReport(PersonalPoorInfoEntity ppi) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(ppi.getIGMIntegrityApplyInfoGuid());
		IGMIntegrityApplyInfo igmiai = new IGMIntegrityApplyInfo();
		igmiai.setGuid(IdUtil.randomUUID());
		igmiai.setName(applyInfo.getName());
		igmiai.setDescription(applyInfo.getDescription());
		igmiai.setApplyType(applyInfo.getApplyType());
		igmiai.setArea(applyInfo.getArea());
		if("保存并上报".equals(ppi.getSaveOrReport())) {
			igmiai.setState("已上报");
			igmiai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		}else {
			igmiai.setState("未上报");
		}
		SysUser currentUser = ShiroUtils.getSysUser();
		igmiai.setOperLoginName(currentUser.getLoginName());
		igmiai.setOperName(currentUser.getUserName());
		igmiai.setOperUnitGuid(String.valueOf(currentUser.getDeptId()));
		PersonalPoorInfoEntity ppia = (PersonalPoorInfoEntity) XMLUtil.convertXmlStrToObject(PersonalPoorInfoEntity.class, applyInfo.getPersonnalPoorInfo());
		ppia.setUndoReason(ppi.getUndoReason());
		igmiai.setCompanyWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setCompanyPoorInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setPersonalWellInfo("<?xml version=\"1.0\" encoding=\"gb2312\"?><PsDataPacket><Standard /><Undo /></PsDataPacket>");
		igmiai.setPersonnalPoorInfo(XMLUtil.convertToXml(ppia));
		igmiai.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		igmiai.setApplyWay("撤销");
		igmiai.setDataGuid(ppi.getGuid());
		PersonalPoorInfoEntity personalPoor = new PersonalPoorInfoEntity();
		personalPoor.setUndoReason(ppi.getUndoReason());
		personalPoor.setUndoOperLoginName(currentUser.getLoginName());
		personalPoor.setUndoOperName(currentUser.getUserName());
		personalPoor.setUndoApplyDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		personalPoor.setGuid(ppi.getGuid());
		int a = integrityInformationAddMapper.insertIGMIntegrityApplyInfo(igmiai);
		int b = integrityInformationAddMapper.updateIGMPersonnalPoorInfo(personalPoor);
		return a+b;
	}
	

	@Override
	@Transactional
	public int peopleBadBehaviorUndoSaveAndReportUpdate(PersonalPoorInfoEntity ppie) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(ppie.getIGMIntegrityApplyInfoGuid());
		PersonalPoorInfoEntity ppiea = (PersonalPoorInfoEntity) XMLUtil.convertXmlStrToObject(PersonalPoorInfoEntity.class, applyInfo.getPersonnalPoorInfo());
		ppiea.setUndoReason(ppie.getUndoReason());
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
		igmai.setGuid(ppie.getIGMIntegrityApplyInfoGuid());
		igmai.setPersonnalPoorInfo(XMLUtil.convertToXml(ppiea));
		PersonalPoorInfoEntity personalPoor = new PersonalPoorInfoEntity();
		personalPoor.setGuid(ppie.getGuid());
		personalPoor.setUndoReason(ppie.getUndoReason());
		if("保存并上报".equals(ppie.getSaveOrReport())) {
			igmai.setState("已上报");
			igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		}else {
			igmai.setState("未上报");
		}
		int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
		int b = integrityInformationAddMapper.updateIGMPersonnalPoorInfo(personalPoor);
		return a+b;
	}

	@Override
	@Transactional
	public int peopleBadBehaviorUndoApprove(PersonalPoorInfoEntity ppi, String reasonContent) {
		SysUser currentUser = ShiroUtils.getSysUser();
		if("通过".equals(ppi.getSaveOrReport())) {
			IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
			igmai.setGuid(ppi.getIGMIntegrityApplyInfoGuid());
			igmai.setState("审核通过");
			igmai.setPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
			PersonalPoorInfoEntity personalPoorInfo = new PersonalPoorInfoEntity();
			personalPoorInfo.setUndoPassDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			personalPoorInfo.setGuid(ppi.getGuid());
			personalPoorInfo.setIsReported("已撤销");
			int b = integrityInformationAddMapper.updateIGMPersonnalPoorInfo(personalPoorInfo);
			IGMAuditRecord igmar = new IGMAuditRecord();
			igmar.setGuid(IdUtil.randomUUID());
			igmar.setDataGuid(ppi.getIGMIntegrityApplyInfoGuid());
			igmar.setType("行为信息撤销");
			igmar.setConclusion("通过");
			igmar.setOpinion(reasonContent);
			igmar.setOperLoginName(currentUser.getLoginName());
			igmar.setOperName(currentUser.getUserName());
			igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int c = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
			return a+b+c;
		}else if("不通过".equals(ppi.getSaveOrReport())) {
			IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
			igmai.setGuid(ppi.getIGMIntegrityApplyInfoGuid());
			igmai.setState("审核退回");
//			IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(ppi.getIGMIntegrityApplyInfoGuid());
//			PersonalPoorInfoEntity personalPoorInfo = (PersonalPoorInfoEntity) XMLUtil.convertXmlStrToObject(PersonalPoorInfoEntity.class, applyInfo.getPersonnalPoorInfo());
//			if(!StringUtils.isEmpty(personalPoorInfo.getUndoReason())) {
//				personalPoorInfo.setUndoReason(null);
//				igmai.setPersonnalPoorInfo(XMLUtil.convertToXml(personalPoorInfo));
//			}
			int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
			int b = integrityInformationAddMapper.updateIGMPersonnalPoorInfoNoPass(ppi.getGuid());
			IGMAuditRecord igmar = new IGMAuditRecord();
			igmar.setGuid(IdUtil.randomUUID());
			igmar.setDataGuid(ppi.getIGMIntegrityApplyInfoGuid());
			igmar.setType("行为信息撤销");
			igmar.setConclusion("不通过");
			igmar.setOpinion(reasonContent);
			igmar.setOperLoginName(currentUser.getLoginName());
			igmar.setOperName(currentUser.getUserName());
			igmar.setPubDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			int c = integrityInformationAddMapper.insertIGMAuditRecord(igmar);
			return a+b+c;
		}
		return 0;
	}

	@Override
	public List<String> selectIGMPersonalPoorInfoByDateadd(String idcard) {
		// TODO Auto-generated method stub
		return integrityInformationAddMapper.selectIGMPersonalPoorInfoByDateadd(idcard);
	}

	@Override
	public boolean judgeQualificationsUndoPeoplePoor(String idcard, String qualif) {
		List<String> strList = integrityInformationAddMapper.selectIGMPersonalPoorInfoByDateadd(idcard);
		if(CollUtil.contains(strList, qualif)) {
			return true;
		}
		return false;
	}

	@Override
	public IGMAuditRecord selectIGMAuditRecordByGuidTopOne(String dataGuid) {
		// TODO Auto-generated method stub
		return integrityInformationAddMapper.selectIGMAuditRecordByGuidTopOne(dataGuid);
	}

	@Override
	@Transactional
	public int enterprisesGoodBehaviorRectSaveAndReport(CompanyWellInfoEntity cwie) {
		IGMIntegrityApplyInfo applyInfo = integrityInformationAddMapper.selectIGMIntegrityApplyInfoByGuid(cwie.getIGMIntegrityApplyInfoGuid());
		CompanyWellInfoEntity cwea = (CompanyWellInfoEntity) XMLUtil.convertXmlStrToObject(CompanyWellInfoEntity.class, applyInfo.getCompanyWellInfo());
		cwea.setUndoReason(cwie.getUndoReason());
		IGMIntegrityApplyInfo igmai = new IGMIntegrityApplyInfo();
		igmai.setGuid(cwie.getIGMIntegrityApplyInfoGuid());
		igmai.setCompanyWellInfo(XMLUtil.convertToXml(cwea));
		SysUser currentUser = ShiroUtils.getSysUser();
		CompanyWellInfoEntity companyWell = new CompanyWellInfoEntity();
		companyWell.setGuid(cwie.getGuid());
		companyWell.setUndoReason(cwie.getUndoReason());
		if("保存并上报".equals(cwie.getSaveOrReport())) {
			igmai.setState("已上报");
			igmai.setReportDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
			companyWell.setUndoOperLoginName(currentUser.getLoginName());
			companyWell.setUndoOperName(currentUser.getUserName());
			companyWell.setUndoApplyDate(DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MS_PATTERN));
		}else {
			igmai.setState("未上报");
			igmai.setReportDate(null);
		}
		int a = integrityInformationAddMapper.updateIGMIntegrityApplyInfo(igmai);
		int b = integrityInformationAddMapper.updateIGMCompanyWellInfo(companyWell);
		return a+b;
	}
}
